-module(cbrowser_block).
-include_lib("nitrogen/include/wf.inc").
-compile(export_all).

						%Builders
assemble_header(X) ->
    X.

assemble_menu(X) ->
    Body = [
	    #p{},
	    #rounded_panel{ color=gray,
			    body=[
				  #label {text="Vos derniers codes"},
				  #table {rows=[
						#tablerow { cells=[
								   #tablecell { id=cbb_last }
								  ]}   
					       ]}
				 ],
			    style="width:100%;"
			   }
	   ],
    case hglobals:vget(helper:id_me(), connected) of
	true ->
	    X ++ Body;
	_ ->
	    X
    end.


assemble_body(X) ->
    X.
						%Wiring

wire() ->
    Module = hglobals:vget(helper:id_me(), caller),
    case hglobals:vget(helper:id_me(), connected) of
     	true ->
     	    Module:exec( 
     	      fun(_) -> 
     		      lists:foldr( 
     			fun({ID, Name}, _) ->
    				wf:insert_bottom(cbb_last, #panel{body=#link{text=Name, actions=helper:act(?MODULE, {open, ID})}}),
				[]
     			end,
			[],
			db:get_last_created_code(db:name_to_id(member, wf:user() )))
     	      end, {} ),
	    ok;
     	_ -> ok
    end.
						%Behavior
behave(_) ->
    ok.
						%Events
event(_) ->
    ok.
